import { type BaseListReq, type BaseResp } from '#/api/model/baseModel';
import { requestClient } from '#/api/request';

import {
  type DepartmentInfo,
  type DepartmentListResp,
} from './model/departmentModel';

enum Api {
  CreateDepartment = '/sys-api/department/create',
  DeleteDepartment = '/sys-api/department/delete',
  GetDepartmentById = '/sys-api/department/info',
  GetDepartmentList = '/sys-api/department/list',
  UpdateDepartment = '/sys-api/department/update',
}

/**
 * @description: Get department list
 */

export const getDepartmentList = (params: BaseListReq) => {
  return requestClient.get<DepartmentListResp>(Api.GetDepartmentList, {
    params,
  });
};

/**
 *  @description: Create a new department
 */
export const createDepartment = (params: DepartmentInfo) => {
  return requestClient.post<BaseResp>(Api.CreateDepartment, params);
};

/**
 *  @description: Update the department
 */
export const updateDepartment = (params: DepartmentInfo) => {
  return requestClient.put<BaseResp>(Api.UpdateDepartment, params);
};

/**
 *  @description: Delete departments
 */
export const deleteDepartment = (id: number) => {
  return requestClient.delete<BaseResp>(`${Api.DeleteDepartment}/${id}`);
};

/**
 *  @description: Get department By ID
 */
export const getDepartmentById = (id: number | string) => {
  return requestClient.get<DepartmentInfo>(`${Api.GetDepartmentById}/${id}`);
};
